//
//  RadioDetailViewController.m
//  A_Project_DLS151129_SQ
//
//  Created by 151129-49宋强 on 16/1/21.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "RadioDetailViewController.h"
#import "MusicPlayViewController.h"

@interface RadioDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *dataArr;
@end

@implementation RadioDetailViewController
- (void)dealloc
{   [_dataArr release];
    [_tableView release];
    [_detailModel release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = self.detailModel.title;
      //主页图片
    [self creatImgView];
    //数据处理
    [self dataHandle];
    //创建tableView
    [self creatTableView];
}
- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 185, self.view.frame.size.width, self.view.frame.size.height - 185 - 64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
    [_tableView release];
    //注册重用池
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
   }
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
//cell样式
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];
    Model *m = _dataArr[indexPath.row];
    cell.textLabel.text = m.title;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"收听人数:%@",m.musicVisit];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:m.coverimg] placeholderImage:[UIImage imageNamed:@"coffe.png"]];
    return cell;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
- (void)dataHandle
{
    NSString *urlStr = @"http://api2.pianke.me/ting/radio_detail";
    NSDictionary *dic = @{@"radioid":_detailModel.radioid,@"start":@0, @"client":@2, @"limit":@10};
    [PWNetWorking POSTWithURL:urlStr body:dic completion:^(id result) {
        NSArray *arr = result[@"data"][@"list"];
        self.dataArr = [Model modelHanderWithArray:arr];
        [_tableView reloadData];
    }];
}

- (void)creatImgView
{
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
    [imgView sd_setImageWithURL:[NSURL URLWithString:self.detailModel.coverimg] placeholderImage:[UIImage imageNamed:@"coffe.png"]];
    [self.view addSubview:imgView];
    
}
//点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MusicPlayViewController *musicVC = [[MusicPlayViewController alloc] init];
    Model *m = _dataArr[indexPath.row];
    //传递Model参数
    musicVC.mm = m;
    [self.navigationController pushViewController:musicVC animated:YES];
    //[musicVC release];
#pragma mark - 通知中心传值
    [[NSNotificationCenter defaultCenter] postNotificationName:@"音乐" object:m userInfo:nil];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
